package yunjiao.javatutorials.guava.concurrent;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * 预热模式
 *
 * @author yangyunjiao
 */
public class WarmingUpRateLimiterExample {
    public static void main(String[] args) {
        // 创建预热限流器：每秒5个许可，预热时间3秒
        RateLimiter rateLimiter = RateLimiter.create(5.0, 3, TimeUnit.SECONDS);

        for (int i = 0; i < 10; i++) {
            double waitTime = rateLimiter.acquire();
            System.out.printf("任务 %d 执行，等待时间: %.4f秒%n", i, waitTime);
        }
    }
}
